//
//  TravelNoteTableViewCell.m
//  B
//
//  Created by Sunpeng on 15/11/9.
//  Copyright © 2015年 wangzhan. All rights reserved.
//

#import "TravelNoteTableViewCell.h"

@implementation TravelNoteTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 0.947 * WIDTH, 0.225*HIGHT)];
    self.myImageView.layer.masksToBounds = YES;
    self.myImageView.layer.cornerRadius = 8.0;
    //    self.myImageView.layer.borderWidth = 1.0;
    
    [self.contentView addSubview:self.myImageView];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.053*WIDTH, 15, 0.8*WIDTH, 0.045*HIGHT)];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17*XHIGHT];
    [self.contentView addSubview:self.nameLabel];
    
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.053*WIDTH, 0.06*HIGHT, 0.213*WIDTH, 0.037*HIGHT)];
    self.dateLabel.font = [UIFont systemFontOfSize:14*XHIGHT];
    self.dateLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14*XHIGHT];
    
    self.dateLabel.textColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.dateLabel];
    
    self.dayCount = [[UILabel alloc]initWithFrame:CGRectMake(0.267*WIDTH, 0.06*HIGHT, 0.267*WIDTH, 0.037*HIGHT)];
    self.dayCount.font = [UIFont systemFontOfSize:14*XHIGHT];
    self.dayCount.font = [UIFont fontWithName:@"Helvetica-Bold" size:14*XHIGHT];
    
    self.dayCount.textColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.dayCount];
    
    self.wayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.053*WIDTH, 0.195*HIGHT, 0.133*WIDTH, 0.037*HIGHT)];
    self.wayLabel.font = [UIFont systemFontOfSize:13*XHIGHT];
    self.wayLabel.textColor = [UIColor whiteColor];
    self.wayLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13*XHIGHT];
    
    [self.contentView addSubview:self.wayLabel];
    
    self.likeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.213*WIDTH, 0.195*HIGHT, 0.213*WIDTH, 0.037*HIGHT)];
    self.likeLabel.font = [UIFont systemFontOfSize:13*XHIGHT];
    self.likeLabel.textColor = [UIColor whiteColor];
    self.likeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13*XHIGHT];
    
    [self.contentView addSubview:self.likeLabel];
}

-(void)setNoteM:(TravelNoteModel *)noteM
{
    _noteM = noteM;
    
    
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:_noteM.cover_image_default] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    self.nameLabel.text = _noteM.name;
    //NSLog(@"self.nameLabel.tex = %@",_noteM.name);
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY.MM.dd"];
    //    NSString *dateStr = [NSString stringWithFormat:@"%ld",_noteM.date_added];
    //
    //    NSDate *date = [formatter dateFromString:dateStr];
    //    NSString* dateString = [formatter stringFromDate:date];
    //    [formatter release];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:_noteM.date_added];
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    
    self.dateLabel.text = confromTimespStr;
    
    self.dayCount.text = [NSString stringWithFormat:@"%ld天",_noteM.day_count];
    self.wayLabel.text = [NSString stringWithFormat:@"%ld足迹",_noteM.waypoints];
    self.likeLabel.text = [NSString stringWithFormat:@"%ld喜欢",_noteM.recommendations];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
